package tests.create;

import static org.junit.Assert.fail;

import model.Budget;
import model.BudgetFactory;
import model.Line;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.workplicity.util.Helper;
import org.workplicity.worklet.WorkletContext;

import cc.test.bridge.LineInterface;

/*
 * 
 * Attempts to create a budget with a line that has a name
 * 
 */

public class SetLineNameTest00
{
	Budget budget;
	BudgetFactory factory;
	LineInterface line;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	@Before
	public void setUp() throws Exception
	{
		factory = new BudgetFactory();
		budget = (Budget) factory.create();
        budget.setName("Test budget");
        budget.setDescription("This is a test budget.");
        line = budget.createLine();
        budget.add(line);
	}

	@After
	public void tearDown() throws Exception
	{
		Helper.delete( (Line)line, "Lines", WorkletContext.getInstance());
		Helper.delete( (Budget)budget, "Budgets", WorkletContext.getInstance());
	}

	@Test
	public void test()
	{
		 try
         {
			try
			{
				line.setName("Test Line");
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
			 
			 Boolean successful = budget.commit();
			 
			 if(!successful)
			 {
				fail("Could not set line name");
			 }
			 else
			 {
				 System.out.println("Line commited. SetLineNameCreateTest00.java passed.");
			 }
         }
		 catch(Exception e)
		 {
			 e.printStackTrace();
			 fail("Setting line name failed with exception " + e);
		 }
	}
}